
# http://wenbo1188.github.io/2017/07/23/cppcheck-manual-chinese/

OPTION(XCMAKE_ENABLE_CPPCHECK "enable cppcheck. default off" OFF)
IF(XCMAKE_ENABLE_CPPCHECK)
    find_program(CMAKE_C_CPPCHECK NAMES cppcheck)
    if (CMAKE_C_CPPCHECK)
            message("-- CppCheck found : ${CMAKE_C_CPPCHECK}")
            message("-- current source dir : ${CMAKE_CURRENT_SOURCE_DIR}")
            message("-- source dir : ${CMAKE_SOURCE_DIR}")
            message("-- config-exclude: ${CMAKE_SOURCE_DIR}/xthird_part")
            set(CMAKE_EXPORT_COMPILE_COMMANDS on)
            set(CMAKE_CXX_CPPCHECK "cppcheck")
            set(CMAKE_C_CPPCHECK "cppcheck")
            list(   APPEND CMAKE_C_CPPCHECK                 
                    "-j 4"
                    "--project=${CMAKE_SOURCE_DIR}/build/compile_commands.json"
                    "--force"
                    "--enable=all"
                    "--config-exclude=${CMAKE_SOURCE_DIR}/xthird_part"
            )
    endif()
endif()
